﻿using AnlianCommon.Common.Domains.ProductionManagement;
using AnlianCommon.Common.DTO;
using AnlianCommon.Common.Infrastructure.IRepository;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace SheepCommon.API.SheepCommands
{
    public class SheepBloodlineQueryHandler : IRequestHandler<SheepBloodlineQueryCommand, Result>
    {
        private readonly IBaseRepository<SheepArchives> _sheepArchivesRepository;

        public SheepBloodlineQueryHandler(IBaseRepository<SheepArchives> sheepArchivesRepository)
        {
            _sheepArchivesRepository = sheepArchivesRepository;
        }
        /// <summary>
        /// 查询系谱
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(SheepBloodlineQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            var list = await (await _sheepArchivesRepository.GetAll()).Where(c => c.RecordAuricle == request.Code).FirstOrDefaultAsync();
            result.Data = list;
            return result;
        }
    }
}
